<%-- 
    Document   : formEmpIntervenant
    Created on : 26 févr. 2013, 12:17:01
    Author     : ali
--%>


<%@page import="java.util.HashMap"%>
<%@page import="java.util.ArrayList"%>
<%@page import="EDT.obj.Formation"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                
        <title>Ajouter une UE</title>
            <link rel="stylesheet" href="Accueil.css" />
            <link rel="SHORTCUT ICON" href="./edt.jpg" />
            
             <script language="JavaScript">
            
            
            function miseAjour(cpt){
                 var select = document.createElement('select');
                select.setAttribute("name", "periode");
                select.setAttribute("id", "periode");
                var option;
                //alert(nbGp);
                var i=1;
                
                while (i<= cpt)
                {
                    option = document.createElement('option');
                    option.setAttribute("value", i);
                    option.appendChild(document.createTextNode(i));
                    select.appendChild(option);
                    i++;
                }
                //document.getElementById('grp').removeChild("groupe");
                document.getElementById('prd').replaceChild(select, document.getElementById('periode'));
            }
             </script>
    </head>

    <body>    
         
    <section>

         
    <!--<form method='POST' action='PromoNivGradForm.do'> -->
   <%
    String form ="";
    
    
    ArrayList<Formation> formation = new ArrayList<Formation>();
    
    //if(session.getAttribute("formation") == null|| request.getParameter("formation")==null ||request.getParameter("ue")==null ){
        
        formation = EDT.api.API.getFormation();
        session.setAttribute( "formation", formation );
        
        form += "<form method='POST' action='AjoutUeAc.do' target='section'>";
        form += "<div class='commentaire'>";
        form += "<fieldset>";
        
        
        form +="<legend>    Ajouter une UE  :   </legend>";
        
        

        form +="Formation : <select name='formation'>";
        for (Formation f : formation)
        form +="    <option value='"+f.getId()+"' onclick='miseAjour("+
               f.getPeriodes()+")'>"+f.getNom()+" ID: "+f.getId()+"</option>";
        form +="</select><br/><br/>";
              
        form += "Nom de UE : <input type='text' name='ue'  /><br/><br/>";
        
        form += "<div id=prd>";
        form += "Periode :   <select id='periode' name='periode'>";
        if(formation.size()>0)  
            for (int i = 1; i<= formation.get(0).getPeriodes();i++)
            form += "<option value='"+i+"'>"+i+"</option>";
               
        form += "</select><br/><br/>";
        form += "</div>";
        
   /* }else{
        
    formation = (ArrayList<Formation> ) session.getAttribute("formation");
        form +="<form method='POST' action='AjoutUeAc.do' target='section'>\n";
        form += "<div class='commentaire'>\n";
        form += "<fieldset>";
        
        
        
        form += "<legend>    Choisissiez une periode  :   </legend>";
        form += "<input type='hidden' name='key' value='"+session.getAttribute("key")+"'/>";
        
        String s =request.getParameter("formation");
        form += "<input type='hidden' name='formation' value='"+s+"'/>"; 
        
        form += "<input type='hidden' name='ue' value='"+request.getParameter("ue")+"'/>";
        
        
        form += "Periode :   <select name='periode'>";
        int gg = Integer.parseInt(s);
        for (Formation f : formation)
            if (f.getId() == gg){
              for (int i = 1; i<= f.getPeriodes();i++)
                    form += "<option value='"+i+"'>"+i+"</option>";
            }    
        form += "</select><br/><br/>";
    
        
                session.removeAttribute("formation");
            
       
    }       */ 
        form += "<input type='submit' value='valider'/><br/>";
        out.println(form);
            
    %>
    
   
    
    
    <html:errors/> 
    
    </fieldset>
    
        
    </div>

    </form>
         
    </section>
    </body>
</html>
